// 安装过程
<template>
  <f7-page class="common-page page-tab has-bottom-btns" ptr @ptr:refresh="refreshConfirm">
    <f7-navbar>
      <f7-nav-left>
          <f7-link back icon-material="chevron_left" force></f7-link>
      </f7-nav-left>
      <f7-nav-title>现场拍照</f7-nav-title>
      <f7-nav-right></f7-nav-right>
    </f7-navbar>
    <div class="common-page-content">
      <v-picture-list
          v-if="formId&&equipmentType"
          :props="{ name: 'customName' }"
          :disabled="disabled"
          listName="list7"
          title="管理人员到位情况（现场拍摄）"
          :typeCode="typeCodeList[0]"
          :dataKey="formId"
          :attachCraneType="equipmentType"
          @onAfterQuery="(val)=>list7=val"
          ref="list7"
          :address="address"
          @check="checkItem"
      ></v-picture-list>
      <v-double-confirm
          v-if="formId&&equipmentType"
          :props="{ name: 'customName' }"
          :disabled="disabled"
          listName="list8"
          title="作业过程拍照"
          :typeCode="typeCodeList[1]"
          :dataKey="formId"
          :attachCraneType="equipmentType"
          @onAfterQuery="(val)=>list8=val"
          @check="(name,index,val)=>list8=val"
          ref="list8"
          :address="address"
          :confirmModel="{
            showConfirmBtn,
            pstatus,
            isConOrg,
            isInsOrg
          }"
      ></v-double-confirm>
    </div>
    <!-- <f7-toolbar position="bottom" no-shadow class="fff" v-if="!disabled">
      <f7-button fill class="submit-btn" @click="fnSubmit()">提交</f7-button>
    </f7-toolbar> -->
  </f7-page>
</template>

<script>
import Config from "@/libs/config.js";
import vDoubleConfirm from './v-double-confirm.vue'
export default {
  components: {
    vDoubleConfirm
  },
  props: {
      // disabled:{
      //   type: Boolean,
      //   default: false,
      // },
      // formId:String,
      // equipmentType:String,
      // typeCodeList:Array,
      // showConfirmBtn:{
      //   type: Boolean,
      //   default: false,
      // },
      // isInsOrg:{
      //   type: Boolean,
      //   default: false,
      // },
      // isConOrg:{
      //   type: Boolean,
      //   default: false,
      // },
      // pstatus:{
      //   type:Number|String,
      // }
  },
  data () {
      return {
          models: {
            process:{
              checkTime:'',
              isRequire:true,
              checkMemo:''
            }
          },
          list7:[],
          list8:[],
          address:'',
      }
  },
  computed: {},
  created () {
    this.loadLocation()
    this.getParams()
  },
  methods: {
    getParams(){
      let {disabled,formId,equipmentType,typeCodeList,showConfirmBtn,isInsOrg,isConOrg,pstatus}=this.$f7route.query
      this.disabled=JSON.parse(disabled)
      this.showConfirmBtn=JSON.parse(showConfirmBtn)
      this.isInsOrg=JSON.parse(isInsOrg)
      this.isConOrg=JSON.parse(isConOrg)
      this.formId=formId
      this.equipmentType=equipmentType
      this.pstatus=pstatus
      this.typeCodeList=typeCodeList.split(',')
    },
    // 无此项 处理函数
    checkItem(index,item) {
        this.$util.getPromise(
            `/admin/attachmentFormDetail/saveAllowNone`, 
            { caseId:this.dataKey,dicId:item.id,type:item.isNil?1:0 }
        )
        .then(r => {
            if(!r.success){
                this.$toast('勾选失败！')
            }
        })
    },
    refreshConfirm(done){
      this.$refs.list8.getFileList()
      this.$refs.list7.getFileList()
      done()
    },
    //获取地址
    loadLocation() {
        let self = this
        self.$util.getCurrentPosition(
            (pos) => {
                if (pos.addresses) {
                    self.address = pos.addresses
                } else {
                    self.address = pos.data.name
                }
            },
            (error) => {
                // self.$f7.dialog.toast(
                //     '获取定位失败,请确认是否授权定位功能'
                // )
            }
        )
    },
    fnSubmit(){
      // 校验附件必传项
      let flag1=this.$refs.list7.getUploadedCount()
      let flag2=this.$refs.list8.getUploadedCount()
      if(!flag1||!flag2) return this.$toast('请上传必传检查项附件')
      let arr=[...this.list7,...this.list8]
      let detects=arr.map(item=>{
        return {
          caseId:this.formId,
          dicId:item.id,
          isPass:item.isPass,
          isNil:item.isNil,
        }
      })
      this.$util
      .getPromise("/equipment/eqmCase/saveDetects", {
        detects,
      })
      .then((r) => {
        if(r&&r.success){
          this.$f7.dialog.alert('提交成功',()=>{
            // this.$f7router.back()
            this.$f7.views.current.router.back({force:true})
          });
        }else{
          this.$f7.dialog.alert(r.message || '提交失败');
        }
      }).catch(err=>{
        console.log(err);
      });
    },
  },
  mounted () {},
  
}
</script>

<style lang="less" scoped>
@import url('../../../../assets/css/commonPage.less');
.submit-btn {
    flex: 1;
    margin: 0 10px;
    border-radius: 24px;
}
/deep/ .accordion{
  background: #fff;
  margin-top: 10px!important;
}
</style>
